//
//  SoundWaveToNative.m
//  Staff
//
//  Created by Jayce on 15/1/28.
//
//

#import "SoundWaveToNative.h"
#import "BOSSSoundWaveController.h"
#import "NSData-AES.h"
#import "JSONKit.h"

@interface SoundWaveToNative ()
@property (assign, nonatomic)BOOL boolTap;
@end
@implementation SoundWaveToNative

- (id)initWithHookCommand:(HookCommand *)hookCommand webView:(UIWebView *)webView hookViewController:(HookWebViewController *)controller{
    if (self = [super initWithHookCommand:hookCommand webView:webView hookViewController:controller]){
        self.boolTap = NO;
    }
    return self;
}

-(void)excute{
    BOSSSoundWaveController *soundWave = [[BOSSSoundWaveController alloc] initWithNibName:@"BOSSSoundWaveController" bundle:nil];
    soundWave.hookWebViewController = self.hookViewController;
    NSUserDefaults *defs = [NSUserDefaults standardUserDefaults];
    NSData *data1 = [defs objectForKey:@"customerInfo"];
    NSData *encryptedData = [NSData dataWithData:data1];
    NSData *saveData = [encryptedData AES256DecryptWithKey:secureToken];
    NSString *userInfo = [[NSString alloc] initWithData:saveData encoding:NSUTF8StringEncoding];
    
    NSDictionary *dic = [userInfo objectFromJSONString];
    NSLog(@"dic===%@",dic);
    
    //将customerInfo数据保存到本地
    NSString *userID = [dic objectForKey:@"account"];
    [defs setObject:userID forKey:@"account"];
    NSString *location = [dic objectForKey:@"location"];
    [defs setObject:location forKey:@"location"];
    [defs synchronize];
    
    NSString *isboss = [dic objectForKey:@"secureToken"];
    if (isboss == nil ||[isboss length] == 0) {
        soundWave.isBoss = NO;
    }else{
        soundWave.isBoss = YES;
    }
    soundWave.HTMLView = self.webView;
    if (!self.boolTap) {
        self.boolTap = YES;
        [self.hookViewController.navigationController pushViewController:soundWave animated:YES];
    }
    [[NSNotificationCenter defaultCenter] postNotificationName:COMMAND_EXCUTE_DONE_NOTIFICATION object:self];

}



@end
